package com.itrus.spring.inject.controller;

import com.itrus.spring.inject.service.DeptService;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class InjectBeanController {
    /**
     * 解决方式：
     * 1. 修改字段名称
     * 2. @Resource 指定 bean 名称
     * 3. @Qualifier 显示指定
     * 4. @Primary 设置优先被注入的 bean
     * <p>
     * 核心源码实现：
     * CommonAnnotationBeanPostProcessor#postProcessProperties
     * CommonAnnotationBeanPostProcessor.autowireResource
     * <p>
     * 注意：默认 bean 名称生成，BeanNameGenerator
     * 1. 内部类
     * 2. 类名前两个字母均为大写
     */

    @Resource
    @Qualifier("devServiceImpl")
//    @Resource(name = "devServiceImpl")
    private DeptService deptService;

    @RequestMapping(path = "/inject/bean")
    public String inject() {
        return deptService.getDesc();
    }
}